package com.projects.candientu.adapters;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.projects.candientu.R;
import com.projects.candientu.utils.DataViewHolder;
import com.projects.candientu.utils.RowData;

public class DataAdapter extends ArrayAdapter<RowData> {
	private LayoutInflater mInflater;

	public DataAdapter(Context context, int resource, int textViewResourceId,
			List<RowData> objects) {
		super(context, resource, textViewResourceId, objects);
		mInflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		DataViewHolder holder = null;
		TextView stt = null;
		TextView idgio = null;
		TextView khoiluong = null;
		TextView thoidiemdo = null;
		RowData rowData = getItem(position);

		if (null == convertView) {
			convertView = mInflater.inflate(R.layout.dataitem, null);
			holder = new DataViewHolder(convertView);
			convertView.setTag(holder);
		}

		holder = (DataViewHolder) convertView.getTag();

		stt = holder.getStt();
		stt.setText(rowData.getmStt());

		idgio = holder.getIDGio();
		idgio.setText(rowData.getmIDGio());
		
		khoiluong = holder.getKhoiLuong();
		khoiluong.setText(rowData.getmKhoiLuong());
		
		thoidiemdo = holder.getThoiDiemDo();
		thoidiemdo.setText(rowData.getmThoiDiemDo());

		return convertView;
	}
}